package com.rongxun.hbwallet.ui.fragment;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rongxun.base.MvpFragment;
import com.rongxun.hbwallet.R;
import com.rongxun.hbwallet.constants.HttpConstants;
import com.rongxun.hbwallet.constants.IntentKey;
import com.rongxun.hbwallet.constants.SPKey;
import com.rongxun.hbwallet.mvp.contract.ITransaction;
import com.rongxun.hbwallet.mvp.presenter.TransactionPresenter;
import com.rongxun.hbwallet.ui.activities.LoginActivity;
import com.rongxun.hbwallet.ui.activities.RechargeActivity;
import com.rongxun.hbwallet.ui.activities.TransferActivity;
import com.rongxun.hbwallet.ui.activities.WalletManagerActivity;
import com.rongxun.hbwallet.ui.activities.WebActivity;
import com.rongxun.utils.ActivityUtils;
import com.rongxun.utils.PreferenceUtils;
import com.rongxun.utils.StatusBarUtil;
import com.rongxun.utils.ToastUtils;
import com.rongxun.utils.wallet.ETHWallet;
import com.rongxun.utils.wallet.WalletDaoUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建者     庄丰泽
 * 创建时间   2018/5/21 10:28
 * 描述  交易
 */

public class TransactionFragment extends MvpFragment<ITransaction.IView, TransactionPresenter> implements ITransaction.IView {
    @BindView(R.id.toolbar_title)
    TextView     mToolbarTitle;
    @BindView(R.id.toolbar_right_text)
    TextView     mRightTitle;
    @BindView(R.id.toolbar)
    Toolbar      mToolbar;
    @BindView(R.id.home_tv_assets)
    TextView     mHomeTvAssets;
    @BindView(R.id.transaction_ll_recharge)
    LinearLayout mTransactionLlRecharge;
    @BindView(R.id.transaction_ll_transferaccounts)
    LinearLayout mTransactionLlTransferaccounts;
    @BindView(R.id.transaction_money)
    TextView     mTransactionMoney;
    @BindView(R.id.yesterday_tv_money)
    TextView     mYesterdayTvMoney;
    @BindView(R.id.marketvalue_tv_money)
    TextView     mMarketvalueTvMoney;
    @BindView(R.id.rise_and_fall)
    TextView     mRiseAndFall;
    @BindView(R.id.home_iv_huobi)
    ImageView    mHuobi;
    @BindView(R.id.home_iv_bytetrade)
    ImageView    mBytetrade;
    @BindView(R.id.home_iv_bitcoin)
    ImageView    mBitcoin;
    @BindView(R.id.home_iv_ripple)
    ImageView    mRipple;

    @Override
    public void showLoading(boolean isShow) {

    }

    @Override
    public void showError(String msg, String errorCode) {
    }

    @Override
    public void checkPermissionsSuccessful(String... permissions) {

    }

    @Override
    public void release() {
    }

    @NonNull
    @Override
    public TransactionPresenter createPresenter() {
        return new TransactionPresenter(this);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_transaction;
    }

    @Override
    protected void init() {
        StatusBarUtil.setToolBarPaddingTop(mToolbar, activity);
        mToolbarTitle.setText(getString(R.string.transaction));
        mRightTitle.setText(getString(R.string.transaction_list));
        mRightTitle.setVisibility(View.VISIBLE);
    }


    @Override
    protected void onLazyLoadOnce() {
        super.onLazyLoadOnce();
    }


    @OnClick({R.id.toolbar_right_text, R.id.transaction_ll_recharge, R.id.transaction_ll_transferaccounts, R.id.home_iv_huobi, R.id.home_iv_bytetrade, R.id.home_iv_bitcoin, R.id.home_iv_ripple})
    public void onViewClicked(View view) {
        String userId = PreferenceUtils.getString(SPKey.USERID, "0");
        if (Integer.parseInt(userId) == 0) {
            ActivityUtils.startActivityWithAnimotion(activity, new Intent(activity, LoginActivity.class));
            return;
        }
        ETHWallet ethWallet = WalletDaoUtils.checkRepeatByUserId(userId);
        if (ethWallet == null) {
            ActivityUtils.startActivityWithAnimotion(activity, new Intent(activity, WalletManagerActivity.class));
            return;
        }
        switch (view.getId()) {
            case R.id.toolbar_right_text:
                ActivityUtils.startActivityWithAnimotion(activity,
                        new Intent(activity, WebActivity.class)
                                .putExtra(IntentKey.WEB_URL, HttpConstants.WEB_ADDRESS.ETH_TRANSACTIONS_URL + ethWallet.getAddress()));
                break;
            case R.id.transaction_ll_recharge:
                ActivityUtils.startActivityWithAnimotion(activity,
                        new Intent(activity, RechargeActivity.class)
                                .putExtra(IntentKey.ETH_WALLET, ethWallet));
                break;
            case R.id.transaction_ll_transferaccounts:
                ActivityUtils.startActivityWithAnimotion(activity,
                        new Intent(activity, TransferActivity.class)
                                .putExtra(IntentKey.ETH_WALLET, ethWallet));
                break;
            case R.id.home_iv_huobi:
                ToastUtils.showToast("go to huobi");
                break;
            case R.id.home_iv_bytetrade:
                ToastUtils.showToast("go to bytetrade");
                break;
            case R.id.home_iv_bitcoin:
                ToastUtils.showToast("go to bitcoin");
                break;
            case R.id.home_iv_ripple:
                ToastUtils.showToast("go to ripple");
                break;
        }
    }
}